package com.springsummer.information.green.beans;

import java.util.List;

public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory implements AutowireCapableBeanFactory{



    @Override
    public Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName) throws Exception {
        Object result = existingBean;

        List<BeanPostProcessor> beanPostProcessorList=getBeanPostProcessors();
        if(!beanPostProcessorList.isEmpty()){
            for (BeanPostProcessor processor : beanPostProcessorList) {
                if(processor instanceof BeanFactoryAware){
                    BeanFactoryAware beanFactoryAware=(BeanFactoryAware)processor;
                    beanFactoryAware.setBeanFactory(this);
                }
                Object current = processor.postProcessBeforeInitialization(result, beanName);
                if (current == null) {
                    return result;
                }
                result = current;
            }
        }

        return result;
    }

    @Override
    public Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName) throws Exception {
        Object result = existingBean;
        for (BeanPostProcessor processor : getBeanPostProcessors()) {
            Object current = processor.postProcessAfterInitialization(result, beanName);
            if (current == null) {
                return result;
            }
            result = current;
        }
        return result;
    }













}

